﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


/// <summary>
/// Summary description for Admin_Permention
/// </summary>
public class Admin_Permention
{


    //delete user
    public static bool delete_user(string username)
    {

        using (SWE2Entities db = new SWE2Entities())
        {
            UserInfo_Table student = (from mt in db.UserInfo_Table where mt.Username == username select mt).FirstOrDefault();

            
            try
            {
               if(student.Username!=username)
            {

                return false;
            }

               if (string.IsNullOrEmpty(username))
               {
                   return false;
               }

               else

                   db.UserInfo_Table.Remove(student);
               db.SaveChanges();
               return true;
            }
                   


           
            catch
            {
                return false;
            }
           
        }
    }







    //Delete question 

    public static bool delete_Question(string question)
    {

        using (SWE2Entities db = new SWE2Entities())
        {

            Question_Table q = (from mt in db.Question_Table where mt.Question == question select mt).FirstOrDefault();
            int i = q.ID;
            Answer_Table ans = (from mt in db.Answer_Table where mt.ID == i select mt).FirstOrDefault();


            try
            {
                if (string.IsNullOrEmpty(question))
                {
                    return false;
                }

                else if (q.Question != question)
                {
                    return false;

                }



                else


                    db.Answer_Table.Remove(ans);
                db.Question_Table.Remove(q);
                db.SaveChanges();
                return true;

            }

            catch
            {
                return false;
            }

        }
    }
    
    
   
    public static bool delete_answer(string answer)
    {

        using (SWE2Entities db = new SWE2Entities())
        {

            Answer_Table ans = (from mt in db.Answer_Table where mt.Answer == answer select mt).FirstOrDefault();


            try
            {
                if (ans.Answer != answer)
                {

                    return false;
                }

                if (string.IsNullOrEmpty(answer))
                {
                    return false;
                }

                else

                db.Answer_Table.Remove(ans);
                db.SaveChanges();
                return true;
            }
              

            catch
            {
                return false;
            }
            



        }
    }

}



